package com.ali.g308_ai.controller;

import com.ali.g308_ai.pojo.vo.ChatHistoryVO;
import com.ali.g308_ai.service.impl.ChatIdsServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/ai/history")
public class ChatIdsController {

    private final ChatIdsServiceImpl chatHistoryServiceImpl;

    private final ChatMemory chatMemory;

    @RequestMapping("/{type}")
    public List<String> getChatIds(@PathVariable String type) {
        return chatHistoryServiceImpl.getChatIds(type);
    }

    @RequestMapping("/{type}/{chatId}")
    public List<ChatHistoryVO> getChatHistory(@PathVariable String type, @PathVariable String chatId) {
        return chatMemory.get(chatId).stream().map(ChatHistoryVO::new).toList();
    }
}
